// packageC/redPacket/personListDetail/personListDetail.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    rid: '',
    redpack_info: {},
    receive_log_list: [],
    page: 1,
    finished: false,
    customBalance: '', // 自定义余额字样
  },

  onLoad: function (options) {
    let {
      rid
    } = options;
    rid && this.setData({
      rid
    });
    try {
      let balance = wx.getStorageSync('balance');
      this.setData({
        customBalance: balance
      });
    } catch (err) {
      console.log(err);
    }
  },

  onShow: function () {
    this.getData();
  },

  getData() {
    let urlStr = app.getNetAddresss("plugin.redpack-user.frontend.sendLogDetail.index");
    app._getNetWork({
      url: urlStr,
      data: {
        rid: this.data.rid
      },
      success: (res) => {
        if (res.data.result !== 1) {
          wx.showToast({
            title: res.data.msg,
          });
          return;
        }
        let data = res.data.data;
        let finished = false;
        let receive_log = data.receive_log_list;
        if (this.data.page >= receive_log.last_page || receive_log.data.length < receive_log.per_page) {
          finished = true;
        }
        this.setData({
          finished,
          page: (++this.data.page),
          redpack_info: data.redpack_info,
          receive_log_list: receive_log.data
        });
      }
    });
  },

  getMoreData() {
    if (this.data.finished) return;
    let urlStr = app.getNetAddresss("plugin.redpack-user.frontend.sendLogDetail.index");
    app._getNetWork({
      url: urlStr,
      data: {
        rid: this.data.rid,
        page: this.data.page
      },
      success: (res) => {
        if (res.data.result !== 1) {
          wx.showToast({
            title: res.data.msg,
          });
          return;
        }
        let data = res.data.data;
        let finished = false;
        let receive_log = data.receive_log_list;
        if (this.data.page >= receive_log.last_page || receive_log.data.length < receive_log.per_page) {
          finished = true;
        }
        let receive_log_list = this.data.receive_log_list.concat(receive_log.data);
        this.setData({
          finished,
          page: (++this.data.page),
          receive_log_list: receive_log_list
        });
      }
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.getMoreData();
  },


});